package com.tech.doggtv.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tech.doggtv.R;
import com.tech.doggtv.action.OnItemClickListener;

import java.util.ArrayList;

/**
 * @Description: ${todo}(这里用一句话描述这个方法的作用)
 * Created by jl_luo on 2015/9/13.
 * email：dongyangluo@126.com
 */
public class ColumnsAdapter extends RecyclerView.Adapter<ColumnsAdapter.MyViewHolder>{
    private OnItemClickListener itemClickListener;
    private String[] mDatas;
    public ColumnsAdapter( String[] mDatas){
        this.mDatas = mDatas;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        MyViewHolder holder = new MyViewHolder(LayoutInflater.from(
                viewGroup.getContext()).inflate(R.layout.item_columns, viewGroup, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, int i) {
        myViewHolder.tvName.setText(mDatas[i]);
        final int pos = i;
        myViewHolder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickListener.onItemClick(view, pos);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDatas.length;
    }

    class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    {

        TextView tvName;
        View root;
        public MyViewHolder(View view)
        {
            super(view);
            root = view;
            tvName = (TextView) view.findViewById(R.id.tv_name);
        }

        @Override
        public void onClick(View view) {
            Log.v("doggv","!!!!!!!!!!!!!!!!!");
//            itemClickListener.onItemClick(view,pos);
        }
    }

    public void setItemClickListener(OnItemClickListener itemClickListener){
        this.itemClickListener = itemClickListener;
    }
}
